﻿using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Game.Foundation;
using Bruce.Net;
using System.Diagnostics;

namespace Game.Server.ChineseChess
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            ServerStart();
            Console.ReadLine();
        }

        static void ServerStart()
        {
            Console.WriteLine("Begin start the server.");

            ClientDispatcher clientDispatcher = new ClientDispatcher();
            ServerSocket clietnServer = new ServerSocket(GameController.Port, 100, PacketLoader.Default, clientDispatcher);
            clietnServer.Listen();
            clientDispatcher.Loop();

            RegisterToMajorServer();
            Console.WriteLine("start completed.");
        }

        static void RegisterToMajorServer()
        {
            Console.WriteLine("register server.");

            //暂时无包可收
            AsyncWorkSocket connectionToMajor = new AsyncWorkSocket("127.0.0.1", 10087, PacketLoader.Default);
            //Thread.Sleep(3000);
            connectionToMajor.Send(GameController.GeneratePacket());

            Console.WriteLine("register completed.");
        }
    }
}
